<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<header th:replace="admin/header::header-fragment">
</header>
<body>
<shiro:user>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">网站设置</div>
          <div class="layui-card-body" pad15>
            
            <div class="layui-form" wid100 lay-filter="">
              <div class="layui-form-item">
                <label class="layui-form-label">网站标题</label>
                <div class="layui-input-block">
                  <input type="text" name="title" th:value="${setblog.blogSettitle}" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">网站副标题</label>
                <div class="layui-input-block">
                  <input type="text" name="titles" th:value="${setblog.blogSettitles}" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">头像</label>
                <div class="layui-input-inline">
                  <input name="avatar" lay-verify="required" id="LAY_avatarSrc" placeholder="图片地址" th:value="${setblog.blogLogo}" class="layui-input">
                </div>
                <div class="layui-input-inline layui-btn-container" style="width: auto;">
                  <button type="button" class="layui-btn layui-btn-primary test1" id="test1">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                  </button>
                  <button class="layui-btn layui-btn-primary" layadmin-event="avartatPreview">查看图片</button >
                </div>
              </div>
              <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">META关键词</label>
                <div class="layui-input-block">
                  <textarea name="keywords" class="layui-textarea" placeholder="多个关键词用英文状态 , 号分割" th:text="${setblog.blogKeywords}"></textarea>
                </div>
              </div>
              <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">META描述</label>
                <div class="layui-input-block">
                  <textarea name="descript" class="layui-textarea" th:text="${setblog.blogDescription}"></textarea>
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">网站备案号</label>
                <div class="layui-input-block">
                  <input type="text" name="blogicp" th:value="${setblog.blogIcp}" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">站长QQ</label>
                <div class="layui-input-block">
                  <input type="text" name="blogqq" th:value="${setblog.blogQq}" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">网站公告</label>
                <div class="layui-input-block">
                  <textarea name="gonggao" class="layui-textarea" th:text="${setblog.blogGonggao}"></textarea>
                </div>
              </div>
              <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">统计代码</label>
                <div class="layui-input-block">
                  <textarea name="tongji" class="layui-textarea" th:text="${setblog.blogTongji}"></textarea>
                </div>
              </div>
              <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">版权信息</label>
                <div class="layui-input-block">
                  <textarea name="banquan" class="layui-textarea" th:text="${setblog.blogBanquan}"></textarea>
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-input-block">
                  <button class="layui-btn" lay-submit lay-filter="set_website">确认保存</button>
                </div>
              </div>
            </div>
            
          </div>
        </div>
      </div>
    </div>
  </div>
  </shiro:user>
<shiro:guest>
  <footer th:replace="admin/nologin::header-fragment">
  </footer>
</shiro:guest>
  <script src="layuiadmin/layui/layui.js"></script>
  <script>
    layui.config({
      base: 'layuiadmin/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use(['index', 'set','layer','upload'],function (){
      var $ = layui.$
              ,form = layui.form
              ,layer = layui.layer
              ,upload = layui.upload;
      //提交
      form.on('submit(set_website)', function(obj){
        //获取表单参数
        var date = obj.field;
        var keywords = $('textarea[name="keywords"]').val();
        var descript = $('textarea[name="descript"]').val();
        var tongji = $('textarea[name="tongji"]').val();
        var banquan = $('textarea[name="banquan"]').val();
        var gonggao = $('textarea[name="gonggao"]').val();
        //请求接口
        $.post('admin/updateSet',{
          "title":date.title,
          "titles":date.titles,
          "avatar":date.avatar,
          "keywords":keywords,
          "descript":descript,
          "blogicp":date.blogicp,
          "blogqq":date.blogqq,
          "gonggao":gonggao,
          "tongji":tongji,
          "banquan":banquan,
        },function (res){
          if (res.success){
            layer.msg('修改网站信息成功', {
              offset: '15px'
              ,icon: 1
              ,time: 1000
            });
          }else {
            layer.msg('修改网站信息失败', {
              offset: '15px'
              ,icon: 1
              ,time: 1000
            });
          }
        },'json');

        return false;
      });

      //执行实例
      var uploadInst = upload.render({
        elem: '#test1' //绑定元素
        ,url: 'admin/uploadPicture' //上传接口
        ,done: function(res){
          //如果上传失败
          if(res.code > 0){
            return layer.msg('上传失败');
          }
          $("#LAY_avatarSrc").val(res.data.src)
          //上传成功
          return layer.msg('上传成功');
        }
        ,error: function(){
          //演示失败状态，并实现重传
          var demoText = $('#demoText');
          demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
          demoText.find('.demo-reload').on('click', function(){
            uploadInst.upload();
          });
        }
      });
    });
  </script>
</body>
</html>